package exception;

import javax.swing.*;

public class Login {
    private static final String USERNAME="xuexue";
    private static final String PASSWORD="0622";

    public void  userName(String userName) throws UserNameException {
        if(!USERNAME.equals(userName)){
            throw new UserNameException();
        }else{
            System.out.println("用户名输入正确");
        }

    }

    public void password(String password){
        if(!PASSWORD.equals(password)){
            try {
                throw new PasswordException();
            }catch (PasswordException e){
                e.printStackTrace();
            }
        }else {
            System.out.println("密码输入正确");
            System.out.println("登录成功");
        }
    }

    public static void main(String[] args) throws UserNameException{
        Login login=new Login();
        login.userName("xuexue");
        login.password("0622");
    }
}
class UserNameException extends Exception{
    public UserNameException(){
        System.out.println("用户名不正确");
    }
}

class PasswordException extends Exception{
    public PasswordException(){
        System.out.println("密码输入不正确");
    }
}